<?php
/**
 * @file comicpreview.php
 * @author Alejandro Dario Simi
 * @date $Date: 2013-06-07 02:16:25 +0000 (Fri, 07 Jun 2013) $
 *
 * $Id: comicpreview.php 71 2013-06-07 02:16:25Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0/themes/default/controlers/generics/comicpreview.php $
 */

function wcGetComicPreviewAssigns(WCComic &$comic, $css=false) {
	global	$wcProfile;
	global	$wcReadRate;

	$out = array();

	//
	// Setting light URIs
	if(!defined("CP-LIGHT-SET")) {
		global	$wcDefaults;
		global	$wcThemeAssigns;

		$wcThemeAssigns["CP-LIGHT-ON"]		= $wcDefaults["icon-light-on"];
		$wcThemeAssigns["CP-LIGHT-OFF"]		= $wcDefaults["icon-light-off"];
		$wcThemeAssigns["CP-LIGHT-LOADING"]	= $wcDefaults["loading"];

		define("CP-LIGHT-SET", true);
	}
	//
	// Basic information
	$out["CP-ID"]		= $comic->id;
	$out["CP-IMAGE-ID"]	= "IMG_{$comic->id}";
	$out["CP-NAME"]		= $comic->name();
	$out["CP-PREVIEW"]	= $comic->previewUri();
	//
	// Global Rate
	$rates = $wcReadRate->comicReadRate($comic);
	$rates["rate"] = $rates["rate"] === false ? 0 : $rates["rate"];
	$out["CP-RATE-GLOBAL"]		= $rates["rate"];
	$out["CP-RATE-GLOBAL-STARS"]	= $rates["rate"] / 2;
	$out["CP-RATE-VOTES"]		= $rates["votes"];
	//
	// Personal Rate
	if($wcProfile->allowedTo(WC_PERM_COMIC_SET_RATE, WC_PERM_COMIC_SET_READ)) {
		$out["CP-USER-RATE"]	= true;

		$rates = $wcReadRate->readRate($comic);

		if($rates["rate"]["rate"] !== false) {
			$out["CP-RATE"]			= true;
			$out["CP-RATE-PERSONAL"]	= $rates["rate"]["rate"];
			$out["CP-RATE-PERSONAL-STARS"]	= $rates["rate"]["rate"] / 2;
		}

		if($rates["read"]["read"]) {
			$out["CP-READ"]	= true;
		}
	}
	//
	// Adding an extra CSS class.
	if($css) {
		$out["CP-EXTRA-CLASS"]	= $css;
	}

	return $out;
}

?>